﻿Imports System.Runtime.InteropServices

Module Declares
    <DllImport("dwmapi.dll", EntryPoint:="#127", PreserveSig:=False)> Public Sub DwmGetColorizationParameters(ByRef parameters As WDM_COLORIZATION_PARAMS)
    End Sub

    <DllImport("dwmapi.dll", EntryPoint:="#131", PreserveSig:=False)> Public Sub DwmSetColorizationParameters(ByRef parameters As WDM_COLORIZATION_PARAMS, Optional ByVal uUnknown As UInteger = True)
    End Sub

    Public Structure WDM_COLORIZATION_PARAMS
        Public Color1 As UInteger
        Public Color2 As UInteger 'Disabled because unsure of what it does and it doesn't seem to work??? :S
        Public Intensity As Integer
        Public Brightness As UInteger
        Public Transparency As UInteger
        Public GlassRelection As UInteger
        Public Transparency_Disabled As Boolean 'Set to true for no transparency, like windows 8? LOL
    End Structure

    Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer
    Public Declare Function GetForegroundWindow Lib "user32" () As Long
    Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As IntPtr, ByVal WinTitle As String, ByVal MaxLength As Integer) As Integer
    Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Integer

    Public Function GetProcessNameByHandle(ByVal Handle As IntPtr)
        Dim sSave As String
        Dim ProcessID As Long

        GetWindowThreadProcessId(Handle, ProcessID)

        Dim tempProc As Process = Process.GetProcessById(ProcessID)

        Dim processName As String = tempProc.ProcessName

        sSave = Space(GetWindowTextLength(Handle) + 1)
        GetWindowText(Handle, sSave, Len(sSave))
        sSave = Microsoft.VisualBasic.Left(sSave, Len(sSave) - 1)
        Return processName
    End Function
End Module
